<template>
  <div class="app-container">
    <el-form :model="selectForm" ref="queryForm" :inline="true">
      <el-form-item label="所属公司">
        <treeselect style="width: 199px;height: 32px" v-model="selectForm.deptId" :options="company"
                    placeholder="请选择所属公司"/>
      </el-form-item>
      <el-form-item label="领用单号">
        <el-input
          v-model="selectForm.receiveCode"
          placeholder="请输入领用单号"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="涉及设备">
        <el-input
          v-model="selectForm.describeDetail"
          placeholder="请输入设备名称"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="领用人">
        <el-input
          v-model="selectForm.receiveUserName"
          placeholder="请输入申请人"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="经手人">
        <el-input
          v-model="selectForm.receiveOperateUserName"
          placeholder="请输入申请人"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="领用时间">
        <el-date-picker
          v-model="selectDate"
          size="small"
          style="width: 240px"
          @change="timechange(selectDate)"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button type="success" icon="el-icon-plus" size="mini" @click="add">领用</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list" stripe border>
      <el-table-column align="center" type="index" label="序号" width="55"/>
      <el-table-column align="center" label="领用单号" property="receiveCode" width="150">
        <template slot-scope="scope" >
          <span style="color: #2196F3;cursor: pointer" @click="details(scope.row)">{{scope.row.receiveCode}}</span>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="涉及设备" property="describeDetail" show-overflow-tooltip></el-table-column>
      <el-table-column  align="center" label="领用部门" property="receiveDeptName" show-overflow-tooltip></el-table-column>
      <el-table-column  align="center" label="领用人" property="receiveUserName" show-overflow-tooltip></el-table-column>
      <el-table-column  align="center" label="经手人" property="receiveOperateUserName" show-overflow-tooltip></el-table-column>
      <el-table-column  align="center" label="领用时间 " property="receiveDate" width="170"> </el-table-column>
      <el-table-column  align="center" label="归还数量" property="returnNumber" width="170"/>
      <el-table-column  align="center" label="领用数量" property="receiveNumber" width="170"/>
      <el-table-column  align="center" label="备注" property="remark" show-overflow-tooltip/>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import request from '@/utils/request'
  import {treeselect} from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    components: {
      Treeselect,
    },
    name: "recipientsReturn.vue",
    data() {
      return {
        selectForm: {
          pageNum: 1,
          pageSize: 10,
          beginReceiveDate: '',
          endReceiveDate: '',
          receiveOperateUserName:'',
          deptId:undefined,
          receiveCode:'',
          describeDetail:'',
          receiveUserName:'',

        },
        company: [],
        selectDate: '',
        loading: false,
        total:0,
        list: [],
      }
    },
    created() {
      this.getTree()
      this.getList()

    },
    methods: {
      timechange:function(row){
        this.selectForm.beginReceiveDate = row[0]
        this.selectForm.endReceiveDate = row[1]
      },
      //所属部门下拉
      getTree() {
        treeselect().then(response => {
          this.company = response.data;
        });
      },
      getList(){
        this.loading = true;
        request({
          url: '/device-receive-api/list',
          method: 'get',
          params:this.selectForm
        }).then(response => {
          this.loading = false;
          this.list = response.rows
          this.total = response.total
        });
      },
      add(){
        var obj = {}
        obj.leixing = 'post'
        this.$router.push({path:'/equipmentCZ/recipientsReturnAdd',query:{data:obj}});
      },
      edit(row){
        var obj = {}
        obj = row
        obj.leixing = 'put'
        this.$router.push({path:'/equipmentCZ/recipientsReturnAdd',query:{data:obj}});
      },
      details(row){
        this.$router.push({path:'/equipmentCZ/recipientsReturnDetail',query:{data:row}});
      },
      //删除
      del(index,row){
        this.$confirm('确定删除该数据吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
    }
  }
</script>

<style scoped>
</style>
